package gui2Dengine;

import grid.Grid;
import grid.Location;
import grid.Node;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.util.ArrayList;

import javax.swing.JPanel;

import tile.Tile;

/**
 * This class is responsible for the rendering of a portion or all of the grid
 * 
 * <br>
 * Properties:
 * <ul>
 * <li><code>Grid</code> from which to render</li>
 * <li><code>DisplayMap</code> to use to render</li>
 * <li><b>double</b> length of side</li>
 * <li><b>float</b> width/fatness of a side</li>
 * <li><b>int</b> x-width number of x-elements to render</li>
 * <li><b>int</b> y-width number of y-elements to render</li>
 * </ul>
 * 
 * A GridPanel defines several rendering methods, using a library such as batik
 * or java2d to effectively render the project.
 * 
 * <br><br>
 * These methods include:
 * <ul>
 * <li>initialize method to draw the grid</li>
 * <li>method to render a grid cell</li>
 * <li>method to render grid</li>
 * <li>method to read-in and save buffered modified tile images</li>
 * <li>?method to transform grid?</li>
 * <li>update method</li>
 * <ul>
 * 
 * @author Sebastian Audet
 * 
 */
public abstract class GridPanel extends JPanel {
    protected Grid grid;
    protected double sidelength;
    protected int xoffset;
    protected int yoffset;
    protected int xunits;
    protected int yunits;
    protected float strokewidth;
    protected ArrayList<Location> visibletiles = new ArrayList<Location>();

    public GridPanel(Grid grid, float strokewidth,int width, int height, int xunits, int yunits, int xoffset, int yoffset) {
	this.grid = grid;
	this.strokewidth = strokewidth;
	this.xoffset=xoffset;
	this.yoffset=yoffset;
	this.setSize(width,height);
	this.xunits=xunits;
	this.yunits=yunits;
    }
    
    public abstract void initmethod(Graphics2D g2);

    public abstract void renderGridNode(Node node, Graphics2D g2);

    /**
     * Renders Grid by first drawing the Grid itself, then by drawing in the
     * images.
     * @param g2 The Graphics2D object with which to render
     */
    public abstract void renderGrid(Graphics2D g2);

    /* (non-Javadoc)
     * @see java.awt.Container#paintComponents(java.awt.Graphics)
     */
    @Override
    public void paintComponent(Graphics g)
    {
	super.paintComponent(g);
	painter(g.create());
    }

    public abstract void painter(Graphics g);
    
    public abstract boolean moveTile(Tile tile, Node originatingNode,Node receivingNode);

    public abstract boolean moveTile(Tile tile, Location oloc, Location rloc);
    
    public abstract boolean removeTile(Tile tile, Location loc);
    
    public abstract boolean removeTile(Tile tile, Node node);
    
    public abstract boolean addTile(Tile tile, Node node);
    
    public abstract boolean addTile(Tile tile, Location loc);
    
    public abstract void eraseNode(Node node);
    
    public abstract void eraseNode(Location loc);
    
    public abstract Node getNode(Point point);
    
    /**
     * Moves the tile to an adjacent empty spot.<br><br>
     * 
     * The empty spots are number 1 upwards beginning at 9'oclock and panning down and right 
     * @param tile The Tile to move
     * @param node The Node from which to move it
     * @param dir The integer direction to move it in
     * @return Whether or not the Tile was moved
     */
    public abstract boolean move(Tile tile,Node node,int dir);
    
    public static void pl(Object string)
    {
	System.out.println(string);
    }
    
}
